package o;

import android.content.res.Resources;
import android.os.Build.VERSION;
import android.util.Log;
import android.util.LongSparseArray;
import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;
import java.lang.reflect.Field;
import java.util.Map;

public class ak {
    private static boolean ʻ;
    private static Field ʼ;
    private static boolean ʽ;
    private static Field ˊ;
    private static Class ˋ;
    private static boolean ˎ;
    private static boolean ˏ;
    private static Field ॱ;

    public static void ॱ(@NonNull Resources resources) {
        if (VERSION.SDK_INT < 28) {
            if (VERSION.SDK_INT >= 24) {
                ˎ(resources);
            } else if (VERSION.SDK_INT >= 23) {
                ˏ(resources);
            } else if (VERSION.SDK_INT >= 21) {
                ˊ(resources);
            }
        }
    }

    @RequiresApi(21)
    private static void ˊ(@NonNull Resources resources) {
        if (!ˎ) {
            try {
                ॱ = Resources.class.getDeclaredField("mDrawableCache");
                ॱ.setAccessible(true);
            } catch (Throwable e) {
                Log.e("ResourcesFlusher", "Could not retrieve Resources#mDrawableCache field", e);
            }
            ˎ = true;
        }
        if (ॱ != null) {
            Map map;
            try {
                map = (Map) ॱ.get(resources);
            } catch (Throwable e2) {
                Log.e("ResourcesFlusher", "Could not retrieve value from Resources#mDrawableCache", e2);
                map = null;
            }
            if (map != null) {
                map.clear();
            }
        }
    }

    @RequiresApi(23)
    private static void ˏ(@NonNull Resources resources) {
        Object obj;
        if (!ˎ) {
            try {
                ॱ = Resources.class.getDeclaredField("mDrawableCache");
                ॱ.setAccessible(true);
            } catch (Throwable e) {
                Log.e("ResourcesFlusher", "Could not retrieve Resources#mDrawableCache field", e);
            }
            ˎ = true;
        }
        if (ॱ != null) {
            try {
                obj = ॱ.get(resources);
            } catch (Throwable e2) {
                Log.e("ResourcesFlusher", "Could not retrieve value from Resources#mDrawableCache", e2);
            }
            if (obj == null) {
                ˏ(obj);
            }
        }
        obj = null;
        if (obj == null) {
            ˏ(obj);
        }
    }

    @RequiresApi(24)
    private static void ˎ(@NonNull Resources resources) {
        if (!ʻ) {
            try {
                ʼ = Resources.class.getDeclaredField("mResourcesImpl");
                ʼ.setAccessible(true);
            } catch (Throwable e) {
                Log.e("ResourcesFlusher", "Could not retrieve Resources#mResourcesImpl field", e);
            }
            ʻ = true;
        }
        if (ʼ != null) {
            Object obj;
            try {
                obj = ʼ.get(resources);
            } catch (Throwable e2) {
                Log.e("ResourcesFlusher", "Could not retrieve value from Resources#mResourcesImpl", e2);
                obj = null;
            }
            if (obj != null) {
                Object obj2;
                if (!ˎ) {
                    try {
                        ॱ = obj.getClass().getDeclaredField("mDrawableCache");
                        ॱ.setAccessible(true);
                    } catch (Throwable e22) {
                        Log.e("ResourcesFlusher", "Could not retrieve ResourcesImpl#mDrawableCache field", e22);
                    }
                    ˎ = true;
                }
                if (ॱ != null) {
                    try {
                        obj2 = ॱ.get(obj);
                    } catch (Throwable e222) {
                        Log.e("ResourcesFlusher", "Could not retrieve value from ResourcesImpl#mDrawableCache", e222);
                    }
                    if (obj2 != null) {
                        ˏ(obj2);
                    }
                }
                obj2 = null;
                if (obj2 != null) {
                    ˏ(obj2);
                }
            }
        }
    }

    @RequiresApi(16)
    private static void ˏ(@NonNull Object obj) {
        if (!ˏ) {
            try {
                ˋ = Class.forName("android.content.res.ThemedResourceCache");
            } catch (Throwable e) {
                Log.e("ResourcesFlusher", "Could not find ThemedResourceCache class", e);
            }
            ˏ = true;
        }
        if (ˋ != null) {
            if (!ʽ) {
                try {
                    ˊ = ˋ.getDeclaredField("mUnthemedEntries");
                    ˊ.setAccessible(true);
                } catch (Throwable e2) {
                    Log.e("ResourcesFlusher", "Could not retrieve ThemedResourceCache#mUnthemedEntries field", e2);
                }
                ʽ = true;
            }
            if (ˊ != null) {
                LongSparseArray longSparseArray;
                try {
                    longSparseArray = (LongSparseArray) ˊ.get(obj);
                } catch (Throwable e22) {
                    Log.e("ResourcesFlusher", "Could not retrieve value from ThemedResourceCache#mUnthemedEntries", e22);
                    longSparseArray = null;
                }
                if (longSparseArray != null) {
                    longSparseArray.clear();
                }
            }
        }
    }
}
